<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:s="http://jboss.com/products/seam/taglib"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich" template="layout/template.xhtml">

	<ui:define name="body">
		<rich:panel>
			<f:facet name="header">Formiranje fakture</f:facet>

			<h:form id="fakturaForm">

				<div class="dialog"><h:panelGrid columns="3" rowClasses="prop"
					columnClasses="name,value,errormsg" width="371">

					<h:outputLabel for="brFakture">Br.Fakture</h:outputLabel>
					<h:outputText id="brFakture" value="#{faktura.brojFakture}" />
					<h:message for="brFakture" style="color: red" />

					<h:outputLabel for="datum">Datum</h:outputLabel>
					<rich:calendar id="datum" requiredMessage="Unesite datum"
						value="#{faktura.datum}" required="true" />
					<rich:message  for="datum">
						<f:facet name="passedMarker">
							<h:graphicImage value="/img/passed.gif" />
						</f:facet>
						<f:facet name="errorMarker">
							<h:graphicImage value="/img/errormsg.gif" />
						</f:facet>
					</rich:message>

					<h:outputLabel for="valuta">Valuta</h:outputLabel>
					<rich:calendar id="valuta" requiredMessage="Unesite valutu"
						value="#{faktura.valuta}" required="true" />
					<rich:message for="valuta">
						<f:facet name="passedMarker">
							<h:graphicImage value="/img/passed.gif" />
						</f:facet>
						<f:facet name="errorMarker">
							<h:graphicImage value="/img/errormsg.gif" />
						</f:facet>
					</rich:message>

					<h:outputLabel for="komitent">Komitent</h:outputLabel>
					<h:selectOneMenu converter="#{domainConverter}" id="komitent"
						requiredMessage="Izaberite komitenta" value="#{faktura.komitent}"
						required="true">

						<s:selectItems value="#{fakturaConversation.vratiSveKomitente()}"
							var="kom" label="#{kom.naziv}"
							noSelectionLabel="-izberi komitenta-" />

					</h:selectOneMenu>
					<rich:message for="komitent">
						<f:facet name="passedMarker">
							<h:graphicImage value="/img/passed.gif" />
						</f:facet>
						<f:facet name="errorMarker">
							<h:graphicImage value="/img/errormsg.gif" />
						</f:facet>
					</rich:message>

					<h:outputLabel for="otpremnica">Otpremnica</h:outputLabel>
					<h:inputText id="otpremnica" requiredMessage="Unesite otpremnicu"
						value="#{faktura.otpremnica}" required="true" />
					<rich:message for="telefon">
						<f:facet name="passedMarker">
							<h:graphicImage value="/img/passed.gif" />
						</f:facet>
						<f:facet name="errorMarker">
							<h:graphicImage value="/img/errormsg.gif" />
						</f:facet>
					</rich:message>

					<h:outputLabel for="radniNalog">Radni nalog</h:outputLabel>
					<h:inputText id="radniNalog" requiredMessage="Unesite radni nalog"
						value="#{faktura.radniNalog}" required="true" />
					<rich:message for="radniNalog">
						<f:facet name="passedMarker">
							<h:graphicImage value="/img/passed.gif" />
						</f:facet>
						<f:facet name="errorMarker">
							<h:graphicImage value="/img/errormsg.gif" />
						</f:facet>
					</rich:message>

					<h:outputLabel for="napomena">Napomena</h:outputLabel>
					<h:inputText id="napomena" value="#{faktura.napomena}" />
					<rich:message for="napomena">
						<f:facet name="passedMarker">
							<h:graphicImage value="/img/passed.gif" />
						</f:facet>
						<f:facet name="errorMarker">
							<h:graphicImage value="/img/errormsg.gif" />
						</f:facet>
					</rich:message>

				</h:panelGrid></div>
				<s:div id="buttonsFaktura" styleClass="actionButtons">
					<a4j:commandButton id="save" value="Sacuvaj fakturu"
						rendered="#{faktura.id==null}"
						action="#{fakturaConversation.save}"
						reRender="table,buttonsFaktura,buttonsSavkeFakture" />

					<a4j:commandButton id="update" value="Izmeni fakturu"
						rendered="#{faktura.id!=null}"
						action="#{fakturaConversation.update}"
						reRender="table,buttonsFaktura,buttonsSavkeFakture" />

					<s:button value="Cancel" id="cancel"
						action="#{fakturaConversation.cancel}" />


				</s:div>
			</h:form>
			<br> </br>
			<rich:panel>
				<f:facet name="header">Podaci o stavkama fakture</f:facet>
				<h:form>
					<h:panelGrid id="stavkePanelGrid" columns="3" rowClasses="prop"
						columnClasses="name,value,errormsg" width="371">
						<h:outputLabel for="usluga">Usluga</h:outputLabel>
						<h:selectOneMenu id="usluga" title="-izaberite uslugu-"
							converter="#{domainConverter}" requiredMessage="Izaberite uslugu"
							value="#{stavkaFakture.usluga}" required="true">
							<s:selectItems value="#{fakturaConversation.vratiSveUsluge()}"
								var="u" label="#{u.naziv}" noSelectionLabel="-izaberite uslugu-" />

						</h:selectOneMenu>
						<rich:message for="usluga">
							<f:facet name="passedMarker">
								<h:graphicImage value="/img/passed.gif" />
							</f:facet>
							<f:facet name="errorMarker">
								<h:graphicImage value="/img/errormsg.gif" />
							</f:facet>
						</rich:message>

						<h:outputLabel for="opis">Opis</h:outputLabel>
						<h:inputText id="opis" value="#{stavkaFakture.opis}" />
						<rich:message for="opis">
							<f:facet name="passedMarker">
								<h:graphicImage value="/img/passed.gif" />
							</f:facet>
							<f:facet name="errorMarker">
								<h:graphicImage value="/img/errormsg.gif" />
							</f:facet>
						</rich:message>

						<h:outputLabel for="jmere">Jed. mere</h:outputLabel>
						<h:inputText required="true"
							requiredMessage="Unesite jedinicu mere" id="jmere"
							value="#{stavkaFakture.jedinicaMere}" />
						<rich:message for="jmere">
							<f:facet name="passedMarker">
								<h:graphicImage value="/img/passed.gif" />
							</f:facet>
							<f:facet name="errorMarker">
								<h:graphicImage value="/img/errormsg.gif" />
							</f:facet>
						</rich:message>

						<h:outputLabel for="kolicina">Kolicina</h:outputLabel>
						<h:inputText required="true" requiredMessage="Unesite kolicinu"
							id="kolicina" value="#{stavkaFakture.kolicina}" />
						<rich:message for="kolicina">
							<f:facet name="passedMarker">
								<h:graphicImage value="/img/passed.gif" />
							</f:facet>
							<f:facet name="errorMarker">
								<h:graphicImage value="/img/errormsg.gif" />
							</f:facet>
						</rich:message>

						<h:outputLabel for="cena">Cena</h:outputLabel>
						<h:inputText required="true" requiredMessage="Unesite cenu"
							id="cena" value="#{stavkaFakture.cena}" />
						<rich:message for="cena">
							<f:facet name="passedMarker">
								<h:graphicImage value="/img/passed.gif" />
							</f:facet>
							<f:facet name="errorMarker">
								<h:graphicImage value="/img/errormsg.gif" />
							</f:facet>
						</rich:message>

						<h:outputLabel for="porez">Porez</h:outputLabel>
						<h:selectOneMenu id="porez" converter="#{domainConverter}"
							title="-Izaberite porez-" requiredMessage="Izaberite porez"
							value="#{stavkaFakture.poreskaTarifa}" required="true">
							<s:selectItems value="#{fakturaConversation.vratiSvePoreze()}"
								var="por" label="#{por.naziv}"
								noSelectionLabel="-izberite porez-" />

						</h:selectOneMenu>
						<rich:message for="porez">
							<f:facet name="passedMarker">
								<h:graphicImage value="/img/passed.gif" />
							</f:facet>
							<f:facet name="errorMarker">
								<h:graphicImage value="/img/errormsg.gif" />
							</f:facet>
						</rich:message>

					</h:panelGrid>

					<s:div id="buttonsStavkeFakture" styleClass="actionButtons">
						<a4j:commandButton id="saveStavka" value="Sacuvaj stavku"
							rendered="#{stavkaFakture.rb==null}"
							action="#{fakturaConversation.sacuvajStavku}"
							reRender="table,buttonsStavkeFakture,stavkePanelGrid" />

						<a4j:commandButton id="deleteStavka" value="Obrisi stavku"
							rendered="#{stavkaFakture.rb!=null}"
							action="#{fakturaConversation.obrisiStavku}"
							reRender="table,buttonsStavkeFakture,stavkePanelGrid" />

						<a4j:commandButton id="updateStavka" value="Izmeni stavku"
							rendered="#{stavkaFakture.rb!=null}"
							action="#{fakturaConversation.izmeniStavku}"
							reRender="table,buttonsStavkeFakture,stavkePanelGrid" />

					</s:div>


				</h:form>
				<br></br>
				<h:form>
					<rich:dataTable id="table" value="#{listStavkeFakture}" var="p">
						<rich:column>
							<f:facet name="header">Rb</f:facet>
                 #{p.rb}
                </rich:column>
						<rich:column>
							<f:facet name="header">Usluga</f:facet>
							<a4j:commandLink id="select" ajaxSingle="true"
								value="#{p.usluga.naziv}"
								action="#{fakturaConversation.selectStavkaFakture}"
								reRender="stavkePanelGrid,buttonsStavkeFakture" />
						</rich:column>

						<rich:column>
							<f:facet name="header">Opis</f:facet>
                 #{p.opis}
                </rich:column>
						<rich:column>
							<f:facet name="header">Jed. mere</f:facet>
                 #{p.jedinicaMere}
                </rich:column>

						<rich:column>
							<f:facet name="header">Kolicina</f:facet>
                 #{p.kolicina}
                </rich:column>
						<rich:column>
							<f:facet name="header">Cena</f:facet>
                 #{p.cena}
                </rich:column>

						<rich:column>
							<f:facet name="header">Porez</f:facet>
                 #{p.poreskaTarifa.naziv}
                </rich:column>

					</rich:dataTable>
				</h:form>

			</rich:panel>


		</rich:panel>

	</ui:define>
</ui:composition>
